<?php
namespace app\home\controller;

use app\common\model\TemplateEncyclopedia as TemplateEncyclopediaModel;
use app\common\model\Cate as CateModel;
/**
 * 寺院百科控制器
 * Class Templateencyclopedia
 * @package app\index\controller
 */
class Templateencyclopedia extends Base
{
    /**
     * [index  查看]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $this->getPageAndSize($param);
        $model = new TemplateEncyclopediaModel();
        $map = [];
        try {
            if(!empty($param['con'])){
                $map['title'] = ['like', "%" . $param['con'] . "%"];
            }
            $map['status'] = 1;
            if(!empty($param['cateid'])){
                $map['cateid'] = $param['cateid'];
            }
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map, $this->from, $this->size,'id,title,cover,label');
        } catch (\Exception $e) {
            return admin_json(-1, '获取失败' . $e->getMessage());
        }
        return admin_json(1, '获取成功', [
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
    /**
     * [index  查看]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getcontent()
    {
        $param = input('param.');
        $this->getPageAndSize($param);
        $model = new TemplateEncyclopediaModel();
        $cmodel = new CateModel;
        $map = [];
        try {
            $content = $model->findData($param['id'],'id','id,content,from,title,intro,cateid,label,cover');
            $cate = $cmodel->findData($content['cateid'],'id','cname');
            $content['cname'] = $cate['cname'];
        } catch (\Exception $e) {
            return admin_json(-1, '获取失败' . $e->getMessage());
        }
        return admin_json(1, '获取成功', $content);
    }
}